package org.abettor.jroa;

import java.io.Closeable;
import java.io.IOException;

/**
 * <p>An interface which identifies an establish connection between
 * the client and the server. The <i>Connection</i> object is a long-time-established
 * connection, so the object can also be treated as a session.</p>
 * <p>When the connection is closed, all the resources, both the server side and
 * the client side, could be released.</p>
 * 
 * @author <a href="http://www.abettor.org/" target="_blank">abettor</a>
 *
 */
public interface Connection extends Closeable
{
	/**
	 * Check if the connection is available.
	 * @return
	 * <p>True if it's available. Otherwise false.</p>
	 */
	public boolean isClosed();

	/**
	 * Once a connection is established, it can post objects via itself.
	 * @param obj The frozen object to be post.
	 * @throws IOException
	 */
	public void postObject(Accessible obj) throws IOException;

	/**
	 * One can try to fetch objects if they were post by peer via the connection.
	 * @return A frozen object will be return if success, otherwise it returns 0.
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	public Accessible fetchObject() throws IOException, ClassNotFoundException;
}
